package com.jeejam.product.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.jeejam.framework.base.pojo.Pager;
import com.jeejam.product.pojo.ProductArticle;
import com.jeejam.product.sdk.api.IProductArticleService;
import com.jeejam.product.sdk.dto.ProductArticleDto;
import com.jeejam.product.service.ProductArticleService;
import com.jeejam.util.ShopBeanBuildUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by JACKEY on 2016/3/6.
 */
@Service(version = "1.0.0")
public class ProductArticleDubboService implements IProductArticleService{
    public ProductArticleDubboService() {
        LOGGER.info("zzz ProductDubboService");
    }

    private static final Logger LOGGER = LoggerFactory.getLogger(ProductArticleDubboService.class);

    @Resource
    private ProductArticleService productArticleService;

    @Override
    public void deleteById(int id) {
        productArticleService.deleteById(id);
    }

    @Override
    public ProductArticleDto getById(int id) {
        ProductArticle productArticle = productArticleService.findById(id);
        return ShopBeanBuildUtil.slmCopyBean(productArticle, ProductArticleDto.class);
    }

    @Override
    public void save(ProductArticleDto productArticleDto) {
        ProductArticle productArticle = ShopBeanBuildUtil.slmCopyBean(productArticleDto, ProductArticle.class);
        productArticleService.save(productArticle);
    }

    @Override
    public void update(ProductArticleDto productArticleDto) {
        ProductArticle productArticle = ShopBeanBuildUtil.slmCopyBean(productArticleDto, ProductArticle.class);
        productArticleService.update(productArticle);
    }

    @Override
    public int counts() {
        return productArticleService.counts();
    }

    @Override
    public Pager getPager(int currentPage, int pageSize) {
        return productArticleService.getPager(currentPage, pageSize);
    }

    @Override
    public List<ProductArticleDto> findAllByPage(int currentPage, int pageSize) {
        List<ProductArticle> productArticleList = productArticleService.selectAllByPage(currentPage, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productArticleList, ProductArticleDto.class);
    }

    @Override
    public int countsByUserId(int userId) {
        return productArticleService.countsByUserId(userId);
    }

    @Override
    public int countsByType(String type) {
        return productArticleService.countsByType(type);
    }

    @Override
    public int countsForNew() {
        return productArticleService.countsForNew();
    }

    @Override
    public int countsForHot() {
        return productArticleService.countsForHot();
    }

    @Override
    public int countsForRecommend() {
        return productArticleService.countsForRecommend();
    }

    @Override
    public List<ProductArticleDto> findForUserId(int userId, int page, int pageSize) {
        List<ProductArticle> productArticleList = productArticleService.findForUserId(userId, page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productArticleList, ProductArticleDto.class);
    }

    @Override
    public List<ProductArticleDto> findForNew(int page, int pageSize) {
        List<ProductArticle> productArticleList = productArticleService.findForNew(page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productArticleList, ProductArticleDto.class);
    }

    @Override
    public List<ProductArticleDto> findForHot(int page, int pageSize) {
        List<ProductArticle> productArticleList = productArticleService.findForHot(page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productArticleList, ProductArticleDto.class);
    }

    @Override
    public List<ProductArticleDto> findForRecommend(int page, int pageSize) {
        List<ProductArticle> productArticleList = productArticleService.findForRecommend(page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productArticleList, ProductArticleDto.class);
    }

    @Override
    public List<ProductArticleDto> findByType(String type, int page, int pageSize) {
        List<ProductArticle> productArticleList = productArticleService.findByType(type, page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productArticleList, ProductArticleDto.class);
    }

    @Override
    public List<ProductArticleDto> selectAllByPage(int page, int pageSize) {
        List<ProductArticle> productArticleList = productArticleService.selectAllByPage(page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productArticleList, ProductArticleDto.class);
    }

    @Override
    public int getVotes(int id) {
        return productArticleService.getVotes(id);
    }

    @Override
    public void updateViews(int id) {
        productArticleService.updateViews(id);
    }

    @Override
    public void updateVotes(int votes, int id) {
        productArticleService.updateVotes(votes, id);
    }

    @Override
    public void recommend(int id) {
        productArticleService.recommend(id);
    }

    @Override
    public void cancelRecommend(int id) {
        productArticleService.cancelRecommend(id);
    }

    @Override
    public void trash(int id) {
        productArticleService.trash(id);
    }

    @Override
    public void restore(int id) {
        productArticleService.restore(id);
    }

}
